package com.example.administrator.familfinalcialmanagement.ui.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.example.administrator.familfinalcialmanagement.R;
import com.example.administrator.familfinalcialmanagement.bean.GreenDaoUtils;
import com.example.administrator.familfinalcialmanagement.bean.ToastBean;
import com.example.administrator.familfinalcialmanagement.greendao.gen.ToastBeanDao;
import com.example.administrator.familfinalcialmanagement.ui.BaseActivity;
import com.example.administrator.familfinalcialmanagement.ui.adapter.ToastAdapter;

import java.util.ArrayList;
import java.util.List;

public class ToastActivity extends BaseActivity {
    private TextView tv_number,tv_add;
    private ListView listview;
    private ToastAdapter adapter;
    ToastBeanDao toastBeanDao = GreenDaoUtils.getSingleTon().getmDaoSession().getToastBeanDao();

    List<ToastBean> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_toast);
        init();
    }
    private void init() {
        setBack();
        setTitleText("备忘提醒列表");
        tv_number=findViewById(R.id.tv_number);
        tv_add=findViewById(R.id.tv_add);
        listview=findViewById(R.id.listview);
        tv_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转到新建界面
                startActivity(new Intent(ToastActivity.this,AddToastActivity.class));
            }
        });

    }

    @Override
    protected void onResume() {
        //查找
        list = toastBeanDao.loadAll();
        adapter=new ToastAdapter(ToastActivity.this,list);
        listview.setAdapter(adapter);
        tv_number.setText("共有："+list.size()+"条记录");
        super.onResume();
    }
}
